package com.likou.second_challenge;

import java.util.HashSet;
import java.util.Set;

public class q3 {

    public int lengthOfLongestSubstring(String s) {
        int n = s.length();
        int ans = 0;
        Set<Character> set = new HashSet<>();

        int left = 0;
        int right = 0;
        for (; right < n; right++) {
            while (set.contains(s.charAt(right))) {
                set.remove(s.charAt(left));
                left++;
            }
            set.add(s.charAt(right));
            ans = Math.max(right - left + 1, ans);
        }

        return ans;
    }
}
